package com.lotusyu.share;

import com.alibaba.fastjson.JSON;
import com.lotusyu.share.event.Event;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class BeanFactory {

    public Map<Integer,Class> codeClassMap = new ConcurrentHashMap<>();

    public void put(Integer code,Class cls){
        codeClassMap.put(code,cls);
    }

    public <T extends Event> T parseBean(Integer code,String json){
        Class cls = codeClassMap.get(code);
        Object o = JSON.parseObject(json, cls);
        return (T) o;
    }
}
